package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @DATE: 29/9/2021  10:00
 * @USER: xiaom
 * @Author: 2232683886@qq.com
 * @Description:
 */
@Slf4j
@Service
@Component
public class ProductCateServiceImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;

    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {

        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();

        try {

            List<ItemCat> itemCats = itemCatMapper.selectAll();

            List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);

            allProductCateResponse.setProductCateDtoList(productCateDtos);
            allProductCateResponse.setCode(SysRetCodeConstants.SUCCESS.getCode());
            allProductCateResponse.setMsg(SysRetCodeConstants.SUCCESS.getMessage());
        } catch (Exception e) {
            log.error("ProductCateServiceImpl.getAllProductCate occur Exception: " + e);
            ExceptionProcessorUtils.wrapperHandlerException(allProductCateResponse,e);
        }
        return allProductCateResponse;
    }
}
